Analysis of biodiversity data
Setup
library(knitr)
library(vegan)
library(psych)
library(here)
library(ape)Beta diversity
1. Jaccard
Let’s calculate Jaccard diversity using the data from the power point
# Create dataframes for the two communities:
Grunewald <- data.frame(Species = c('BT', 'Robin', 'Magpie','Roller', 'Swallow', 'GT'),
Abundance = c(3, 2, 2, 1, 2, 4))
Grunewald## Species Abundance
## 1 BT 3
## 2 Robin 2
## 3 Magpie 2
## 4 Roller 1
## 5 Swallow 2
## 6 GT 4
Alex <- data.frame(Species = c('BT', 'Dove', 'Magpie', 'GT', 'Crow'),
Abundance = c(3, 4, 1, 5, 2))
Alex## Species Abundance
## 1 BT 3
## 2 Dove 4
## 3 Magpie 1
## 4 GT 5
## 5 Crow 2
# Now let's get a, b and c needed to calculate Jaccard index
Common <- merge(Grunewald, Alex, by = 'Species') # create a dataframe with only the common species of the two communities
a <- nrow(Common) # get the number of common species
Unique_Grun <- sum(! Grunewald$Species %in% Alex$Species) # get the number of unique species for Grunewald
Unique_Alex <- sum(! Alex$Species %in% Grunewald$Species) # get the number of unique species for Grunewald
J <- a / (a + Unique_Grun + Unique_Alex) # calculate Jaccard index
J ## [1] 0.375
2. Bray-Curtis
# Create dataframes for the two communities:
Grunewald <- data.frame(Species = c('BT', 'Robin', 'Magpie','Roller', 'Swallow', 'GT'),
Abundance = c(3, 2, 2, 1, 2, 4))
Grunewald## Species Abundance
## 1 BT 3
## 2 Robin 2
## 3 Magpie 2
## 4 Roller 1
## 5 Swallow 2
## 6 GT 4
Alex <- data.frame(Species = c('BT', 'Dove', 'Magpie', 'GT', 'Crow'),
Abundance = c(3, 4, 1, 5, 2))
Alex## Species Abundance
## 1 BT 3
## 2 Dove 4
## 3 Magpie 1
## 4 GT 5
## 5 Crow 2
# Now let's get a, b and c needed to calculate Jaccard index
Common <- merge(Grunewald, Alex, by = 'Species') # create a dataframe with only the common species of the two communities
Common$Min <- unlist(lapply(1:nrow(Common), FUN = function(x){min(Common[x, 2:3])})) # get the minimum abundance of each common species between the two communities
Common## Species Abundance.x Abundance.y Min
## 1 BT 3 3 3
## 2 GT 4 5 4
## 3 Magpie 2 1 1
S_Grun <- sum(Grunewald$Abundance) # get the total abundance of all species for Grunewald
S_Alex <- sum(Alex$Abundance) # get the total abundance of all species for Alex
BC <- 2*sum(Common$Min) / (S_Grun + S_Alex) # calculate Bray-Curtis
BC## [1] 0.5517241
Principal Coordinates Analysis
Bird data
First, let’s read the .csv data
# Export dataframe of species abundance and environmental variables for each site
species <- read.csv(here('data','data_berlin','animal_data','birds_berlin_exercise_planillo2021.csv'))
envir <- read.csv(here('data','data_berlin','animal_data','birds_transects_allenvir_100m.csv'))
# Let's look how the bird species data look like
head(species) ## Accipiter_gentilis Acrocephalus_arundinaceus Acrocephalus_palustris
## 1 0 0 0
## 2 0 0 0
## 3 0 0 0
## 4 0 3 0
## 5 0 0 0
## 6 0 2 5
## Acrocephalus_scirpaceus Aegithalos_caudatus Alauda_arvensis Anthus_trivialis
## 1 0 0 0 0
## 2 0 1 0 0
## 3 0 0 0 0
## 4 4 2 0 0
## 5 0 2 2 11
## 6 5 0 9 1
## Apus_apus Buteo_buteo Carduelis_cannabina Carduelis_carduelis
## 1 15 0 0 1
## 2 21 0 0 1
## 3 4 0 0 0
## 4 0 1 0 2
## 5 0 1 1 1
## 6 0 0 1 1
## Carduelis_chloris Certhia_brachydactyla Certhia_familiaris
## 1 2 0 0
## 2 11 11 0
## 3 7 4 0
## 4 2 3 0
## 5 6 2 0
## 6 2 4 0
## Coccothraustes_coccothraustes Columba_livia Columba_oenas Columba_palumbus
## 1 0 1 0 18
## 2 0 0 0 23
## 3 0 5 0 17
## 4 1 0 5 10
## 5 1 0 0 5
## 6 1 0 0 2
## Corvus_corax Corvus_corone Cuculus_canorus Parus_caeruleus Delichon_urbicum
## 1 0 10 0 9 0
## 2 0 11 0 25 0
## 3 0 2 0 18 0
## 4 0 10 2 19 0
## 5 1 6 1 18 0
## 6 0 1 1 7 0
## Dendrocopos_major Dendrocopos_medius Dryocopus_martius Emberiza_citrinella
## 1 0 0 0 0
## 2 8 0 0 0
## 3 1 0 0 0
## 4 10 7 1 0
## 5 4 0 0 20
## 6 4 0 0 8
## Emberiza_schoeniclus Erithacus_rubecula Falco_tinnunculus Ficedula_hypoleuca
## 1 0 0 0 0
## 2 0 9 0 0
## 3 0 5 0 0
## 4 1 14 0 0
## 5 0 10 0 1
## 6 14 5 0 0
## Fringilla_coelebs Garrulus_glandarius Hippolais_icterina Hirundo_rustica
## 1 0 1 0 0
## 2 4 1 0 0
## 3 2 0 0 0
## 4 30 3 0 10
## 5 18 3 2 0
## 6 9 1 1 0
## Lanius_collurio Locustella_naevia Parus_cristatus Luscinia_megarhynchos
## 1 0 0 0 0
## 2 0 0 0 7
## 3 0 0 0 0
## 4 0 0 0 9
## 5 7 2 0 20
## 6 4 1 0 3
## Miliaria_calandra Motacilla_alba Motacilla_flava Muscicapa_striata
## 1 0 0 0 0
## 2 0 2 0 0
## 3 0 0 0 0
## 4 0 1 0 1
## 5 0 2 0 1
## 6 0 1 3 2
## Oriolus_oriolus Parus_major Passer_domesticus Passer_montanus Parus_ater
## 1 0 10 162 0 0
## 2 0 39 121 5 0
## 3 0 18 56 4 0
## 4 2 19 2 0 1
## 5 2 35 18 4 0
## 6 3 10 0 2 0
## Phoenicurus_ochruros Phoenicurus_phoenicurus Phylloscopus_collybita
## 1 0 0 0
## 2 5 7 4
## 3 4 2 0
## 4 0 0 13
## 5 1 6 13
## 6 2 2 5
## Phylloscopus_sibilatrix Phylloscopus_trochilus Pica_pica Picus_viridis
## 1 0 0 4 0
## 2 0 1 4 1
## 3 0 0 0 0
## 4 1 1 0 1
## 5 0 15 1 1
## 6 0 1 0 0
## Parus_palustris Prunella_modularis Regulus_ignicapilla Saxicola_torquatus
## 1 0 0 0 0
## 2 0 1 2 0
## 3 0 0 0 0
## 4 2 0 1 0
## 5 0 1 0 0
## 6 0 0 0 1
## Serinus_serinus Sitta_europaea Streptopelia_decaocto Sturnus_vulgaris
## 1 0 0 0 2
## 2 5 3 0 13
## 3 0 4 0 11
## 4 0 21 0 36
## 5 0 1 0 6
## 6 0 1 0 6
## Sylvia_atricapilla Sylvia_borin Sylvia_communis Sylvia_curruca
## 1 2 0 0 1
## 2 26 0 0 4
## 3 10 0 0 0
## 4 28 1 1 0
## 5 24 5 4 1
## 6 7 0 0 0
## Troglodytes_troglodytes Turdus_merula Turdus_philomelos site
## 1 0 27 0 BE10
## 2 10 37 0 BE11
## 3 4 30 1 BE12
## 4 14 27 11 BE13
## 5 5 54 11 BE14
## 6 3 13 3 BE15
str(species) #29 transects## 'data.frame': 29 obs. of 71 variables:
## $ Accipiter_gentilis : int 0 0 0 0 0 0 0 0 1 0 ...
## $ Acrocephalus_arundinaceus : int 0 0 0 3 0 2 0 0 0 0 ...
## $ Acrocephalus_palustris : int 0 0 0 0 0 5 0 3 4 0 ...
## $ Acrocephalus_scirpaceus : int 0 0 0 4 0 5 0 0 0 2 ...
## $ Aegithalos_caudatus : int 0 1 0 2 2 0 0 0 2 0 ...
## $ Alauda_arvensis : int 0 0 0 0 2 9 0 21 1 0 ...
## $ Anthus_trivialis : int 0 0 0 0 11 1 0 0 0 0 ...
## $ Apus_apus : int 15 21 4 0 0 0 0 0 3 12 ...
## $ Buteo_buteo : int 0 0 0 1 1 0 0 0 0 0 ...
## $ Carduelis_cannabina : int 0 0 0 0 1 1 0 3 1 0 ...
## $ Carduelis_carduelis : int 1 1 0 2 1 1 1 3 1 4 ...
## $ Carduelis_chloris : int 2 11 7 2 6 2 11 6 8 13 ...
## $ Certhia_brachydactyla : int 0 11 4 3 2 4 2 0 1 3 ...
## $ Certhia_familiaris : int 0 0 0 0 0 0 0 0 0 0 ...
## $ Coccothraustes_coccothraustes: int 0 0 0 1 1 1 0 0 0 1 ...
## $ Columba_livia : int 1 0 5 0 0 0 0 0 1 0 ...
## $ Columba_oenas : int 0 0 0 5 0 0 0 0 0 0 ...
## $ Columba_palumbus : int 18 23 17 10 5 2 16 7 13 15 ...
## $ Corvus_corax : int 0 0 0 0 1 0 0 0 1 0 ...
## $ Corvus_corone : int 10 11 2 10 6 1 4 4 8 10 ...
## $ Cuculus_canorus : int 0 0 0 2 1 1 0 3 1 0 ...
## $ Parus_caeruleus : int 9 25 18 19 18 7 20 4 18 15 ...
## $ Delichon_urbicum : int 0 0 0 0 0 0 0 0 2 0 ...
## $ Dendrocopos_major : int 0 8 1 10 4 4 0 0 3 3 ...
## $ Dendrocopos_medius : int 0 0 0 7 0 0 0 0 0 0 ...
## $ Dryocopus_martius : int 0 0 0 1 0 0 0 0 0 0 ...
## $ Emberiza_citrinella : int 0 0 0 0 20 8 0 14 4 0 ...
## $ Emberiza_schoeniclus : int 0 0 0 1 0 14 0 0 1 0 ...
## $ Erithacus_rubecula : int 0 9 5 14 10 5 0 0 4 4 ...
## $ Falco_tinnunculus : int 0 0 0 0 0 0 0 0 1 0 ...
## $ Ficedula_hypoleuca : int 0 0 0 0 1 0 0 0 0 4 ...
## $ Fringilla_coelebs : int 0 4 2 30 18 9 2 2 0 0 ...
## $ Garrulus_glandarius : int 1 1 0 3 3 1 2 2 0 3 ...
## $ Hippolais_icterina : int 0 0 0 0 2 1 0 5 1 2 ...
## $ Hirundo_rustica : int 0 0 0 10 0 0 0 0 1 0 ...
## $ Lanius_collurio : int 0 0 0 0 7 4 0 2 2 0 ...
## $ Locustella_naevia : int 0 0 0 0 2 1 0 2 2 0 ...
## $ Parus_cristatus : int 0 0 0 0 0 0 0 0 1 0 ...
## $ Luscinia_megarhynchos : int 0 7 0 9 20 3 10 6 18 5 ...
## $ Miliaria_calandra : int 0 0 0 0 0 0 0 8 0 0 ...
## $ Motacilla_alba : int 0 2 0 1 2 1 0 0 2 0 ...
## $ Motacilla_flava : int 0 0 0 0 0 3 0 0 0 0 ...
## $ Muscicapa_striata : int 0 0 0 1 1 2 0 0 1 3 ...
## $ Oriolus_oriolus : int 0 0 0 2 2 3 0 0 0 0 ...
## $ Parus_major : int 10 39 18 19 35 10 46 17 28 18 ...
## $ Passer_domesticus : int 162 121 56 2 18 0 104 0 88 90 ...
## $ Passer_montanus : int 0 5 4 0 4 2 6 4 8 8 ...
## $ Parus_ater : int 0 0 0 1 0 0 0 0 0 0 ...
## $ Phoenicurus_ochruros : int 0 5 4 0 1 2 7 0 4 6 ...
## $ Phoenicurus_phoenicurus : int 0 7 2 0 6 2 11 0 12 9 ...
## $ Phylloscopus_collybita : int 0 4 0 13 13 5 7 4 9 3 ...
## $ Phylloscopus_sibilatrix : int 0 0 0 1 0 0 0 0 0 0 ...
## $ Phylloscopus_trochilus : int 0 1 0 1 15 1 0 14 4 3 ...
## $ Pica_pica : int 4 4 0 0 1 0 4 2 5 7 ...
## $ Picus_viridis : int 0 1 0 1 1 0 0 1 0 1 ...
## $ Parus_palustris : int 0 0 0 2 0 0 0 0 0 0 ...
## $ Prunella_modularis : int 0 1 0 0 1 0 1 0 3 1 ...
## $ Regulus_ignicapilla : int 0 2 0 1 0 0 4 0 1 0 ...
## $ Saxicola_torquatus : int 0 0 0 0 0 1 0 2 0 0 ...
## $ Serinus_serinus : int 0 5 0 0 0 0 4 0 7 4 ...
## $ Sitta_europaea : int 0 3 4 21 1 1 0 0 0 3 ...
## $ Streptopelia_decaocto : int 0 0 0 0 0 0 0 0 0 6 ...
## $ Sturnus_vulgaris : int 2 13 11 36 6 6 19 10 17 34 ...
## $ Sylvia_atricapilla : int 2 26 10 28 24 7 14 12 15 7 ...
## $ Sylvia_borin : int 0 0 0 1 5 0 0 3 3 3 ...
## $ Sylvia_communis : int 0 0 0 1 4 0 0 23 0 1 ...
## $ Sylvia_curruca : int 1 4 0 0 1 0 7 3 4 4 ...
## $ Troglodytes_troglodytes : int 0 10 4 14 5 3 6 0 5 2 ...
## $ Turdus_merula : int 27 37 30 27 54 13 39 14 49 32 ...
## $ Turdus_philomelos : int 0 0 1 11 11 3 1 5 1 4 ...
## $ site : chr "BE10" "BE11" "BE12" "BE13" ...
# Data for great tits (Parus major)
hist(species$Parus_major, col = 'grey', main = '', xlab = 'Great tit abundance') # Let's look how the env. data looks like
head(envir) # every line/ row corresponds with a site## site patch.lu patch.area pop_100m
## 1 BE10 park and green area 4762.0000 240.2320426
## 2 BE11 park and green area 22107.5781 41.9517209
## 3 BE12 park and green area 623.8551 64.4663933
## 4 BE13 park and green area 700876.6900 0.2617629
## 5 BE14 brownfield with meadow, shrubs and trees 1119275.5140 0.1640317
## 6 BE15 farmland 754802.5036 0.2794827
## distance_water impervious_surface light noise open_green temp_cooldown
## 1 887.99534 85.708155200 254.0484 52.66811 0.003755813 -0.4034781
## 2 182.70408 48.086350720 253.5432 61.36624 0.147960262 -0.5058560
## 3 846.25954 56.269183550 253.5924 53.33908 0.116351677 -0.4798068
## 4 89.61534 0.003294742 97.9062 22.78204 0.062367094 -0.7988746
## 5 849.76658 7.314871159 248.0444 35.69318 0.517760575 -0.6104055
## 6 1114.94496 3.692755106 238.8065 62.04909 0.692938283 -0.8771918
## temp_day temp_night tree_cover
## 1 21.85441 13.61666 6.983366
## 2 21.74545 13.03693 22.487329
## 3 21.33945 12.66102 19.374208
## 4 28.82046 16.64645 70.116086
## 5 21.35707 10.84691 36.390875
## 6 30.88368 14.75161 19.789344
hist(envir$pop_100m, col = 'grey', main = '', xlab = 'Human population density')hist(envir$noise, col = 'grey', main = '', xlab = 'Noise level')And now let’s fit a PCoA on the species data
# remove site as a column
bird_data <- species[,-71]
rownames(bird_data) <- species$site
# Bray curtis distance between sites based on species abundances
bird_dist <- vegdist(bird_data, method = "bray")
# Principal coordinates analysis or metric multidimensional scaling
birds_pcoa <- cmdscale(bird_dist, k = nrow(bird_data)-1, list. = TRUE)
# Plot of the sites
ordiplot(scores(birds_pcoa, choices=c(1,2)), type="t", main="PCoA with species weighted averages")
abline(h=0, lty=3)
abline(v=0, lty=3)
scores(birds_pcoa)## Dim1 Dim2 Dim3 Dim4 Dim5
## BE10 -0.32649708 0.1199655043 -0.05774427 0.1878895986 -0.032443917
## BE11 -0.05232726 0.1451554948 0.11169700 0.0679375404 0.060787294
## BE12 -0.09367186 -0.0212186123 -0.05728042 -0.0931690603 -0.017329860
## BE13 0.34721298 0.0037468502 0.04689841 0.0525971296 0.031762848
## BE14 0.22809091 -0.1375811356 0.23420701 0.0067478811 0.040541330
## BE15 0.22235941 -0.4077194440 -0.13664195 0.1316452030 0.146482989
## BE16 -0.10440267 0.0694463618 0.14693625 -0.0222574704 0.033662212
## BE17 0.14331749 -0.4433928510 0.08655554 0.1369623415 -0.205629079
## BE18 -0.07870473 -0.0286351686 0.18828575 -0.0145063326 0.069961653
## BE19 -0.12616766 0.0006696531 0.08963510 -0.0009317679 0.004584780
## BE2 0.45275845 0.2036886924 -0.13396045 0.0194824988 -0.124335715
## BE20 -0.26602500 -0.0998174357 -0.20223688 -0.0877422684 0.023430070
## BE21 0.29694126 0.0737349451 0.17233026 -0.0663914618 0.053419083
## BE22 -0.18267006 -0.0107353726 -0.05942331 -0.1253025551 -0.064350757
## BE23 -0.21686386 -0.0054831935 -0.10854350 -0.0896036993 -0.043592076
## BE24 -0.20222099 0.0937987851 -0.04012134 0.1751369484 0.006957131
## BE25 -0.10446188 -0.0480408930 -0.02502407 -0.0958580019 0.024585062
## BE26 -0.07919277 0.0954049007 -0.01759456 0.0410377094 0.118269742
## BE27 -0.09828631 0.0288819500 0.06681340 -0.0893470931 -0.033950591
## BE28 0.45525904 0.0771144627 -0.17768541 0.0097853479 0.003218418
## BE29 -0.16804080 -0.0360222217 0.06705202 -0.1160946317 -0.081903029
## BE3 0.25377754 -0.0196594863 -0.00886709 -0.0877887384 0.092362519
## BE30 -0.12859685 -0.0023289263 0.10110322 -0.0994283572 -0.021922330
## BE4 0.32096898 0.1592135278 0.05243821 -0.0646073304 -0.077315138
## BE5 -0.37518601 0.0269839928 -0.11925306 0.1003718261 0.032960379
## BE6 -0.17755791 -0.0296345171 -0.12647351 -0.0570332457 0.030050967
## BE7 -0.18306027 0.1662171070 0.09890731 0.2460822160 -0.053821268
## BE8 -0.22538237 -0.0721647821 -0.02675874 -0.0844123349 -0.016615051
## BE9 0.46863028 0.0984118122 -0.16525094 0.0187981082 0.000172335
## Dim6 Dim7 Dim8 Dim9 Dim10
## BE10 -0.022952557 0.0079341579 0.022883639 -0.0198948557 -0.0078828418
## BE11 0.046209294 0.0353602907 -0.017144714 0.0322262254 -0.0088504750
## BE12 -0.063834968 -0.0728548227 -0.005907006 -0.0238279506 -0.0322864355
## BE13 -0.212315053 0.1253426299 -0.069510224 -0.0643071120 -0.0002700977
## BE14 0.027665616 -0.0673345792 0.047083201 -0.1131488599 -0.0082929406
## BE15 -0.071803167 -0.1005226380 0.034383282 0.1071643956 0.0055563770
## BE16 0.054407825 0.0636557938 0.061590173 0.0063783894 -0.0272926582
## BE17 0.089288719 0.0820178229 -0.001852374 -0.0195523186 -0.0099670154
## BE18 0.016716124 0.0051424186 0.032566493 -0.0233235092 0.0884596629
## BE19 -0.088805226 0.1063840788 -0.062098946 0.0567103757 0.0311264160
## BE2 -0.009895064 -0.0058998648 0.085216021 0.0171939197 0.0434806131
## BE20 0.038947678 -0.0108555497 0.037545610 -0.0290550325 0.0392020744
## BE21 -0.020875783 -0.0292381589 -0.013148689 0.0307814973 0.0713246122
## BE22 -0.039840340 -0.0490308485 -0.035972405 -0.0361017783 0.0004166153
## BE23 -0.077241150 -0.0430633206 -0.008359514 -0.0664408010 0.0312598615
## BE24 -0.029528282 -0.0140148586 -0.007816883 -0.0617663330 -0.0910184221
## BE25 0.097820320 0.0244068038 -0.093536212 -0.0139622713 0.0053860407
## BE26 0.022181742 0.0379662836 0.083506499 -0.0006474506 -0.0432423611
## BE27 0.070789295 0.0008498683 -0.101233767 0.0971903662 0.0052859715
## BE28 0.047172250 0.0118426139 -0.043072429 -0.0331283661 -0.0064505386
## BE29 -0.111572087 -0.0321639001 0.047498168 0.0736549050 -0.0366817540
## BE3 0.081910426 -0.0187599651 -0.058164766 -0.0238761642 -0.1031003413
## BE30 0.020472271 -0.0463523818 0.083997306 -0.0423041199 0.0304682238
## BE4 -0.004814097 -0.0135727519 0.073537052 0.0693835741 -0.0679552814
## BE5 0.048579778 0.1048867163 0.067038480 0.0281002563 0.0397627031
## BE6 0.012836557 0.0166966014 -0.040843633 -0.0294674402 0.0307605640
## BE7 0.018872708 -0.1650008126 -0.093939476 0.0229028600 0.0286496693
## BE8 -0.006455663 0.0341039801 -0.010155746 0.0525131144 -0.0544614877
## BE9 0.066062834 0.0120743925 -0.014089141 0.0066044839 0.0466132457
## Dim11 Dim12 Dim13 Dim14 Dim15
## BE10 -0.056057458 -0.076149029 0.0351879714 -3.189132e-02 -0.001927465
## BE11 -0.009655319 -0.033146113 -0.0406901312 -4.442599e-02 -0.019291420
## BE12 0.062190684 0.031277720 0.0001973927 -4.299296e-02 0.082246398
## BE13 -0.035829581 0.019500059 -0.0024295380 -1.616959e-02 -0.004164731
## BE14 -0.082317524 -0.011736542 -0.0629682756 -6.043512e-05 0.019387684
## BE15 -0.007286179 -0.032182594 0.0032528868 -1.739606e-02 -0.015575947
## BE16 0.046670908 0.024616702 0.0100619411 -2.623407e-02 -0.034666604
## BE17 0.053910245 0.005976535 -0.0004300301 -3.633188e-03 0.001118927
## BE18 -0.007672416 0.015432374 0.0021099721 6.159117e-02 0.020853802
## BE19 -0.008205237 -0.030531668 0.0391308920 1.766343e-02 0.013131103
## BE2 -0.014365865 -0.058734280 0.0030128465 5.712253e-02 0.054164752
## BE20 -0.049204357 0.034762674 0.0275433215 -1.211664e-02 0.004850499
## BE21 0.104919355 0.005932717 0.0260107788 -1.828211e-03 -0.012451954
## BE22 0.084473574 -0.073134177 -0.0293170194 -6.964173e-04 -0.035759150
## BE23 0.015367937 -0.049484220 -0.0665243328 -3.285475e-03 -0.042885044
## BE24 0.027268977 0.013528678 0.0482791549 2.802373e-02 0.005068488
## BE25 -0.021435695 -0.011258345 0.0514317744 -6.812389e-02 0.041638792
## BE26 0.065999337 -0.015654394 -0.0207994021 -1.100192e-02 0.032916086
## BE27 -0.055019215 -0.046005566 -0.0500989933 -7.381315e-03 0.025555831
## BE28 -0.006931702 0.053276072 -0.0232368315 -2.924044e-02 -0.021979483
## BE29 -0.021936877 0.066578310 0.0035865092 1.333822e-03 0.028788898
## BE3 0.003649844 -0.036509429 0.0124756111 7.673815e-02 0.007996476
## BE30 -0.037070604 -0.014271838 0.0924294362 -2.194875e-02 -0.038513399
## BE4 -0.036802706 0.034273542 -0.0279279043 -3.704182e-02 -0.036187732
## BE5 0.017149861 0.025639857 -0.0665956094 1.226630e-02 0.012337430
## BE6 -0.017367015 0.086833842 -0.0265679997 3.459738e-02 -0.015909427
## BE7 0.004418483 0.057537140 -0.0030105435 1.693319e-02 -0.008950640
## BE8 -0.026031373 0.004607616 0.0218539965 7.246910e-02 -0.042933713
## BE9 0.007169917 0.009024358 0.0440321260 -3.270318e-03 -0.018858456
## Dim16 Dim17 Dim18 Dim19 Dim20
## BE10 0.0052891708 0.0130469500 0.0148000306 -0.0193148817 0.0101940194
## BE11 -0.0049623768 0.0406947353 0.0152618711 0.0008444094 0.0042003162
## BE12 0.0185015708 0.0012160022 0.0198551292 0.0381588594 0.0175030521
## BE13 -0.0069826558 0.0153934021 0.0066356531 0.0008304782 0.0033474751
## BE14 -0.0107597470 0.0031647535 -0.0091647096 0.0057861584 -0.0101794173
## BE15 -0.0107379725 -0.0173256043 0.0014847459 -0.0005509541 0.0009760925
## BE16 -0.0116186109 -0.0097433689 -0.0131773270 0.0165834968 0.0109824084
## BE17 0.0131863792 0.0054515072 0.0077826924 -0.0013839027 0.0013780707
## BE18 -0.0058759828 -0.0160577831 0.0117956750 -0.0089596462 0.0102092270
## BE19 0.0257419303 -0.0304635589 -0.0395954153 0.0327310231 -0.0112167740
## BE2 -0.0170782611 -0.0165667388 -0.0057789617 -0.0084330655 0.0053616284
## BE20 0.0264885716 0.0364297144 -0.0247319849 -0.0045429643 0.0046367588
## BE21 0.0046857065 0.0176284505 0.0074844531 -0.0365464560 0.0071971418
## BE22 -0.0227415644 0.0007289478 -0.0140548897 -0.0085261360 -0.0174942097
## BE23 0.0015581702 -0.0073841528 0.0007626767 0.0117456275 0.0105222016
## BE24 -0.0020085559 -0.0169050504 0.0191366233 -0.0205213048 -0.0089833090
## BE25 -0.0691238247 -0.0279915918 -0.0127015212 -0.0171721596 0.0016229182
## BE26 0.0330589185 -0.0170818468 0.0041461219 -0.0058528573 -0.0154111415
## BE27 0.0459692298 -0.0049999924 0.0299619638 -0.0092670173 -0.0053036514
## BE28 0.0474871595 -0.0180181338 -0.0347864821 -0.0322875542 0.0051937165
## BE29 -0.0140250252 0.0440943318 -0.0112797987 -0.0274537274 -0.0147099612
## BE3 0.0006888078 0.0272182994 -0.0190577102 0.0118007268 0.0047703602
## BE30 0.0328504466 -0.0107486662 0.0052486075 0.0105972292 -0.0074598576
## BE4 -0.0189396871 -0.0345576408 0.0033820090 0.0121560489 0.0028818202
## BE5 -0.0243671455 0.0147156410 -0.0197910818 0.0088756334 -0.0014323751
## BE6 -0.0079139638 -0.0342103684 0.0432903143 -0.0036294183 -0.0094219895
## BE7 -0.0035232289 0.0008340464 -0.0252528986 0.0173279197 0.0007124978
## BE8 -0.0084069152 0.0024771520 0.0091442904 -0.0019923708 0.0160534165
## BE9 -0.0164405440 0.0389605637 0.0291999236 0.0389968052 -0.0161304353
## Dim21
## BE10 -5.919715e-03
## BE11 1.211960e-02
## BE12 4.826735e-03
## BE13 8.133323e-04
## BE14 -1.255091e-04
## BE15 -5.368017e-04
## BE16 -1.456639e-02
## BE17 5.726370e-04
## BE18 -2.741167e-03
## BE19 2.883692e-06
## BE2 1.878231e-03
## BE20 -4.796737e-03
## BE21 1.791118e-04
## BE22 2.782693e-03
## BE23 -6.484870e-03
## BE24 -1.847461e-03
## BE25 1.262183e-03
## BE26 -2.452607e-04
## BE27 -6.097615e-03
## BE28 3.144438e-03
## BE29 -3.825945e-03
## BE3 -1.276814e-03
## BE30 1.073290e-02
## BE4 6.108306e-05
## BE5 6.668769e-03
## BE6 8.637308e-04
## BE7 6.656770e-04
## BE8 7.543964e-03
## BE9 -5.653686e-03
# Add weighted average projection of species
birds_wa <- wascores(birds_pcoa$points[,1:2], bird_data)
text(birds_wa, rownames(birds_wa), cex=0.7, col="red")Add environmental values
# Add environmental variables
rownames(envir) <- (envir$site)
envir_data <- envir[,-1]
# population density
pop_fit <- envfit(birds_pcoa$points, envir_data$pop_100m)
ordiplot(scores(birds_pcoa, choices=c(1,2)), type="t", main="PCoA with species weighted averages")
abline(h=0, lty=3)
abline(v=0, lty=3)
plot(pop_fit, p.max = 0.05, col = "red")# multiple environmental variables
head(envir_data)## patch.lu patch.area pop_100m
## BE10 park and green area 4762.0000 240.2320426
## BE11 park and green area 22107.5781 41.9517209
## BE12 park and green area 623.8551 64.4663933
## BE13 park and green area 700876.6900 0.2617629
## BE14 brownfield with meadow, shrubs and trees 1119275.5140 0.1640317
## BE15 farmland 754802.5036 0.2794827
## distance_water impervious_surface light noise open_green
## BE10 887.99534 85.708155200 254.0484 52.66811 0.003755813
## BE11 182.70408 48.086350720 253.5432 61.36624 0.147960262
## BE12 846.25954 56.269183550 253.5924 53.33908 0.116351677
## BE13 89.61534 0.003294742 97.9062 22.78204 0.062367094
## BE14 849.76658 7.314871159 248.0444 35.69318 0.517760575
## BE15 1114.94496 3.692755106 238.8065 62.04909 0.692938283
## temp_cooldown temp_day temp_night tree_cover
## BE10 -0.4034781 21.85441 13.61666 6.983366
## BE11 -0.5058560 21.74545 13.03693 22.487329
## BE12 -0.4798068 21.33945 12.66102 19.374208
## BE13 -0.7988746 28.82046 16.64645 70.116086
## BE14 -0.6104055 21.35707 10.84691 36.390875
## BE15 -0.8771918 30.88368 14.75161 19.789344
envir_data2 <- envir_data[,c("impervious_surface", "pop_100m", "noise", "tree_cover", "open_green")]
env_fit <- envfit(birds_pcoa$points, envir_data2)
ordiplot(scores(birds_pcoa, choices=c(1,2)), type="t", main="PCoA with species weighted averages",
cex = 1)
abline(h=0, lty=3, col = "grey80")
abline(v=0, lty=3, col = "grey80")
# points(birds_wa, col = "blue")
text(birds_wa, rownames(birds_wa), cex=0.7, col="blue")
plot(env_fit, col = "red", bg = "grey80")Overlap the grouping of the sites
# grouping the sites
envir$imperv_classes <- ifelse(envir$impervious_surface < 25, "low",
ifelse(envir$impervious_surface > 75, "high", "medium"))
plot(birds_pcoa$points, type = "n", xlab = "PC1", ylab = "PC2",
main = "PCoA with imperviousness classes")
points(birds_pcoa$points, col = "black", bg = "orange", pch = 21)
text(birds_pcoa$points, rownames(birds_pcoa$points), cex = 0.7)
ordiellipse(birds_pcoa, envir$imperv_classes, col = 1:3,
draw = "polygon")
ordispider(birds_pcoa, envir$imperv_classes, col = 1:3,
label = TRUE)Exercise
See script on alpha diversity exercise Q 4
Session Info
Sys.time()## [1] "2023-02-22 11:03:22 CET"
#git2r::repository() ## uncomment if you are using GitHub
sessionInfo()## R version 4.2.2 (2022-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19044)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8
## [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
## [5] LC_TIME=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ape_5.6-2 here_1.0.1 psych_2.2.9 vegan_2.6-4
## [5] lattice_0.20-45 permute_0.9-7 knitr_1.41
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.9 highr_0.9 bslib_0.4.1 compiler_4.2.2
## [5] jquerylib_0.1.4 rmdformats_1.0.4 tools_4.2.2 digest_0.6.30
## [9] jsonlite_1.8.4 evaluate_0.18 nlme_3.1-160 mgcv_1.8-41
## [13] rlang_1.0.6 Matrix_1.5-1 cli_3.4.1 rstudioapi_0.14
## [17] yaml_2.3.6 parallel_4.2.2 xfun_0.35 fastmap_1.1.0
## [21] stringr_1.4.1 cluster_2.1.4 sass_0.4.4 systemfonts_1.0.4
## [25] rprojroot_2.0.3 grid_4.2.2 R6_2.5.1 textshaping_0.3.6
## [29] rmarkdown_2.18 bookdown_0.30 magrittr_2.0.3 htmltools_0.5.3
## [33] MASS_7.3-58.1 splines_4.2.2 mnormt_2.1.1 ragg_1.2.4
## [37] stringi_1.7.8 cachem_1.0.6